package network;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


public class MyFile extends File {
	byte [] buffer;
	boolean delete;
	final boolean directory;
	
	public MyFile(String path) throws IOException{
		super(path);
		directory = this.isDirectory();
		this.delete = false;
		bufferize();
	}
	
	public MyFile(String path, boolean to_delete) throws IOException{
		super(path);
		directory = this.isDirectory();
		if(to_delete){
			this.delete = true;
			// Pas besoin de bufferize le fichier pour le supprimer
		}
		else {
			this.delete = false;
			bufferize();
		}
		
	}
	
	private void bufferize() throws IOException{
		if(! this.isDirectory()){
			this.buffer  = new byte [(int) this.length()];
			FileInputStream fis = new FileInputStream(this);
			BufferedInputStream bis = new BufferedInputStream(fis);
			bis.read(buffer,0,buffer.length);
		}
	}
	
	public byte[] getData(){
		return this.buffer;
	}
	
	
}
